<%@ tag pageEncoding="UTF-8" %>  
<%@include file="../pages/common/taglibs.jsp" %>

<%@ attribute name="currentPage" required="true" rtexprvalue="true" %>  
<%@ attribute name="pagesize" required="true" rtexprvalue="true" %>  
<%@ attribute name="totalRows" required="true" rtexprvalue="true" %>  
<%@ attribute name="totalPages" required="true" rtexprvalue="true" %>  
<%@ attribute name="url" required="true" rtexprvalue="true" %>  
<%@ attribute name="params" required="true" rtexprvalue="true" %> 

			<div class="page-list">
			
				<c:if test="${totalPages <= 9 }">
					<c:if test="${currentPage > 1 }">
	                    <span class="first-page">上一页</span>
	                </c:if>
					<c:forEach begin="1" end="${totalPages }" var="item">
                		<span class="${currentPage == item?'selectednum':'num' }">${item }</span>
                	</c:forEach>
	                <c:if test="${currentPage < totalPages }">
	                    <span class="last-page">下一页</span>
	                </c:if>
				</c:if>
				
				<c:if test="${totalPages > 9 }">
				
					<c:if test="${currentPage > 1 }">
	                     <span class="first-page">上一页</span>
	                </c:if>
	                
	                <c:if test="${currentPage <= 5 }">
	                	<c:forEach begin="1" end="7" var="item">
	                		<span class="${currentPage == item?'selectednum':'num' }">${item }</span>
	                	</c:forEach>
	                	<span class="num">...</span>
	                	<span class="num">${totalPages }</span>
	                </c:if>
	                <c:if test="${currentPage > 5 }">
	                	<span class="num">1</span>
	                	<span class="num">...</span>
	                	
	                	<c:if test="${(totalPages - currentPage )>4}">
	                		<c:forEach begin="${currentPage - 2 }" end="${ currentPage}" var="item">
		                		<span class="${currentPage == item?'selectednum':'num' }">${item }</span>
		                	</c:forEach>
		                	<c:forEach begin="${currentPage +1 }" end="${ currentPage + 2}" var="item">
		                		<span class="num">${item }</span>
		                	</c:forEach>
		                	<span class="num">...</span>
		                	<span class="num">${totalPages }</span>
	                	</c:if>
	                	
	                	<c:if test="${(totalPages - currentPage )<=4}">
	                		<c:forEach begin="${currentPage - (2 + (4-(totalPages - currentPage ))) }" end="${ currentPage}" var="item">
		                		<span class="${currentPage == item?'selectednum':'num' }">${item }</span>
		                	</c:forEach>
		                	<c:forEach begin="${currentPage +1 }" end="${ totalPages}" var="item">
		                		<span class="${currentPage == item?'selectednum':'num' }">${item }</span>
		                	</c:forEach>
	                	</c:if>
	                	
	                	
	                </c:if>
	                <c:if test="${currentPage - totalPages < 0 }">
	                    <span class="last-page">下一页</span>
	                </c:if>
				</c:if>
                </div>
                
                <script>
                var page = {
                		currentPage:${currentPage},
                		totalPages:${totalPages},
                		url:"${url}",
                		params:${params},
                		genRequestUrl:function(newpage){
                			var returl = this.url;
                			if(this.url.indexOf('?') != -1){
                				for(var key in this.params){
                					returl += "&"+key+"="+this.params[key]; 
                				}
                				returl += "&currentPage="+newpage;
                			}else{
                				returl += "?q";
                				for(var key in this.params){
                					returl += "&"+key+"="+this.params[key]; 
                				}
                				returl += "&currentPage="+newpage;
                			}
                			return returl;
                		}
                };
                $(function(){
                	//数字页码点击处理
                	$('.page-list .num').click(function(){
                		var url = page.genRequestUrl($(this).text());
                		window.location.href=url;
                	});
                	//跳转到上一页
                	$('.first-page').click(function(){
                		var url = page.genRequestUrl(page.currentPage -1);
                		window.location.href=url;
                	});
                	//跳转到下一页
                	$('.last-page').click(function(){
                		var url = page.genRequestUrl(page.currentPage +1);
                		window.location.href=url;
                	});
                });
                </script>